Skip to content

Followup to #895: rename dissat_sat function and use struct rather than tuple for return values#930

Merged
apoelstra merged 2 commits into
rust-bitcoin:masterfrom
apoelstra:2026-04/followup-895
Apr 28, 2026
Merged

Followup to #895: rename dissat_sat function and use struct rather than tuple for return values#930
apoelstra merged 2 commits into
rust-bitcoin:masterfrom
apoelstra:2026-04/followup-895

Conversation

@apoelstra

Copy link
Copy Markdown
Member

Makes naming more consistent and reduces confusion caused by having a tuple with two entries of the same type.

@apoelstra

Copy link
Copy Markdown
Member Author

On 5097641 successfully ran local tests

@trevarj trevarj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much nicer!

ACK 6c2dc1a

Comment thread src/miniscript/satisfy/sat_dissat.rs Outdated
Comment on lines +486 to +489
let (dissats, sats): (Vec<_>, Vec<_>) = sat_dissats
.into_iter()
.map(|SatDissat { dissat, sat }| (dissat, sat))
.unzip();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

                let (dissats, sats): (Vec<_>, Vec<_>) = stack
                    .drain(stack.len() - thresh.n()..)
                    .map(|SatDissat { dissat, sat }| (dissat, sat))
                    .unzip();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah, I should combine these two let lines.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in an earlier iteration of this PR I was still using the sat_dissat variable, but clearly I am not now..

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, and I don't think my "allocation-wasteful" comment actually applies anymore. Nice.

}
}

/// The (dissatisfaction, satisfaction) pair for an `older` fragment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit, can ignore: Find and replace on "(dissatisfaction, satisfaction) pair" to just "satisfaction and dissatisfaction" or "SatDissat" in the doc comments.

@apoelstra apoelstra force-pushed the 2026-04/followup-895 branch from 5097641 to 5870086 Compare April 24, 2026 14:30
@apoelstra

Copy link
Copy Markdown
Member Author

Fixed both nits.

Comment thread src/miniscript/satisfy/sat_dissat.rs Outdated
// order of our tuple.
let (dissats, sats): (Vec<_>, Vec<_>) = stack
.drain(stack.len() - thresh.n()..)
.into_iter()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for still using into_iter()? It compiled without it for me.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah clippy picked up on it too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, nice, we're saving LOC all over the place. Fixed.

It is too easy to get the satisfactions and dissatisfactions confused. Use
a struct with named fields.

Curiously, outside of this module dissatisfactions are never used, so we can
keep the `dissat` field private. (Well, this is a bit of a sketchy thing to
say -- dissatisfactions **are** used by the Satisfaction::thresh and
thresh_mall functions, but those functions take dissats and sats as independent
Vecs they can manipulate, rather than taking a SatDissat struct.)
The name of the function no longer implies its return value (which is a
struct rather than a tuple that needs to be carefully ordered). So change
the name to be consistent with the name of the module.
@apoelstra apoelstra force-pushed the 2026-04/followup-895 branch from 5870086 to f7f1689 Compare April 24, 2026 14:41
@apoelstra

Copy link
Copy Markdown
Member Author

On f7f1689 successfully ran local tests

@tcharding tcharding left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK f7f1689

@tcharding

Copy link
Copy Markdown
Member

I didn't do any grepping because it sounds like @trevarj already did.

@apoelstra apoelstra merged commit 09175e3 into rust-bitcoin:master Apr 28, 2026
26 checks passed
apoelstra added a commit that referenced this pull request May 20, 2026
…on` in the satisfier

6fd1cc3 miniscript: change tap_leaf_internal to return an option (Andrew Poelstra)
15c093f miniscript: use downcasting logic for computing a taproot leaf hash (Andrew Poelstra)
f946d4a clippy: fix a couple new nightly lints (Andrew Poelstra)

Pull request description:

  Now that we have #895 and #930 we have room to change the API for helpers to the satisfaction functions.
  
  Change the method `tap_leaf_internal`, which currently computes the "tapleaf hash" for an arbitrary Miniscript, even non-Taproot ones, to detect whether this is a Taproot script and only compute the tapleaf hash for Taproot scripts.
  
  Once we are returning an `Option` from `tap_leaf_internal`, we can change a bunch of satisfaction code that currently takes a `Ctx` paramater and introspects it to determine whether we are in Taproot mode or not, and have it simply use the `Option` to decide.
  
  Aside from speeding up and simplifying the code, this removes several instances of the `Ctx` parameter, which we want to eventually eliminate.


ACKs for top commit:
  apoelstra:
    ACK 6fd1cc3; successfully ran local tests
  tcharding:
    ACK 6fd1cc3


Tree-SHA512: c4f6f41684f7adf3b0d7c7eb0cd4d3d40be8ffef872a8e918d430ddf26ae2b7e089e8534e7fea8eb64cbf0c51b58ad63637799356e5e4d4f071abf0cf7aa51d8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants